< previous page page_399 next page >

Page 399
z0419-01.gif
Figure 12.20
Rotating the point (x, y) until it lies on the X axis.
e10a6a0a59f035e870d90cca05b85fce.gif
 z0419-02.gif
Using this fact, you can write a Visual Basic routine that initializes a transformation matrix to rotate a point until it lies in the X axis without calling the relatively slow Sin and Cos functions.
e10a6a0a59f035e870d90cca05b85fce.gif
' Create a rotation matrix that rotates the point
' (x, y) onto the X axis.
Public Sub m2RotateIntoX(Result() As Single, _
    ByVal x As Single, ByVal y As Single)
Dim d As Single

    m2Identity Result
    d = Sqr(x * x + y *y)
    Result(1, 1) = x / d
    Result(1, 2) = -y / d
    Result(2, 1) = -Result(1, 2)
    Result(2, 2) = Result(1, 1)
End Sub
With these routines as tools, you can build more complicated combinations of transformations. The following routines use these tools to create transformation matrices for scaling around a point other than the origin, reflection around an arbitrary line, and rotation around a specified point.
e10a6a0a59f035e870d90cca05b85fce.gif
' Create a scaling matrix for scaling by factors
' of sx and sy at the point (x, y).
Public Sub m2ScaleAt(Result() As Single, _
    ByVal sx As Single, ByVal sy As Single, _
    ByVal x As Single, ByVal y As Single)
Dim T(1 To 3, 1 To 3) As Single
Dim S(1 To 3, 1 To 3) As Single
Dim T_Inv(1 To 3, 1 To 3) As Single
Dim M(1 To 3, 1 To 3) As Single

 
< previous page page_399 next page >